EmptyDroplets (FDR <= 0.1) + scDblFindersetwd("/media/jacopo/Elements/re_align/MM/PRJNA732205/SAMN19314103/SRR14629341/")
# Load the libraries (from Sarah script + biomart)
library(tidyverse) # packages for data wrangling, visualization etc
library(Seurat) # scRNA-Seq analysis package
library(clustree) # plot of clustering tree
library(ggsignif) # Enrich your 'ggplots' with group-wise comparisons
library(clusterProfiler) #The package implements methods to analyze and visualize functional profiles of gene and gene clusters.
library(org.Hs.eg.db) # Human annotation package neede for clusterProfiler
library(ggrepel) # extra geoms for ggplo2
library(patchwork) #multiplots
library(reticulate)
Load and do the QC for the cellranger data
#list.files(".")
dat <- Read10X(data.dir ="./out/counts_filtered/")
dat <- CreateSeuratObject(dat) # Create the seurat object from the 10x data
kb.initial <- dat@assays[["RNA"]]@counts@Dim[[2]]
cat("Initial number of cells:", kb.initial,
"\nNumber of genes:", dat@assays[["RNA"]]@counts@Dim[[1]])
## Initial number of cells: 10357
## Number of genes: 36601
Empty cells were already filtered, check for % mt RNA and death markers:
# first calculate the mitochondrial percentage for each cell
dat$percent_mt <- PercentageFeatureSet(dat, pattern="^MT.")
# make violin plots
mt_rna = 5
max_counts = 15000
# Check some feature-feature relationships
# % mt RNA vs n Counts, n Features vs n Counts
# Check some feature-feature relationships
# % mt RNA vs n Counts, n Features vs n Counts
VlnPlot(dat, features = c("nCount_RNA", "nFeature_RNA", "percent_mt")) + geom_hline(yintercept=mt_rna, linetype = "dotted")
plot1 <- FeatureScatter(dat, feature1 = "nCount_RNA", feature2 = "percent_mt")
plot1 <- plot1 + geom_hline(yintercept=mt_rna, linetype = "dotted")
plot2 <- FeatureScatter(dat, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
plot2 <- plot2 + geom_vline(xintercept = max_counts, linetype = "dotted")
plot1
plot2
## cells retained by mt RNA content ( 5 %): 5925
## percentage of retained cells: 57.21 %
## cells retained by counts ( 15000 ): 5882
## percentage of retained cells: 56.79 %
Check the distribution of the cells with low counts and control death markers:
min_counts = 800
hist(dat@meta.data$nCount_RNA, breaks = 100, xlab = "Counts")
hist(dat@meta.data$nCount_RNA, breaks = 1000, xlab = "Counts", xlim = c(0,5000))
hist(dat@meta.data$nCount_RNA, breaks = 10000, xlab = "Counts", xlim = c(0,1000))
abline(v=min_counts, col="red", lty = 3)
The evident peak of cells with < 200 counts could contain dying
cells.
# Subset the dataset to focus only on those cells with low counts
dat.lowcount <- subset(dat, subset = nCount_RNA < min_counts)
# Get the mean of the counts for each gene and sort them decreasing
meanCounts <- rowMeans(GetAssayData(object = dat.lowcount, slot = 'counts'))
meanCounts <- sort(meanCounts, decreasing = T)
# A boxplot can help to observe the distribution of the means
#boxplot(meanCounts)
# Print the most highly expressed genes
head(meanCounts, 30)
## IGLC2 MALAT1 JCHAIN IGHG3 IGHGP RPLP1 HBB IGLC1
## 80.543961 30.661192 27.121417 10.028663 5.743639 3.828986 3.295974 2.884058
## RPL41 RPS18 B2M IGLC3 RPL10 IGKC RPL13A RPS14
## 2.781965 2.776167 2.739130 2.705314 2.655717 2.492110 2.469243 2.200000
## RPLP2 SSR4 RPL34 RPS19 IGHG1 RPL13 RPS27A RPS6
## 2.126892 2.024799 1.800644 1.700483 1.695330 1.570370 1.562319 1.341385
## RPS23 RPS27 RPS15 MT-ND2 RPL18A RPS15A
## 1.333011 1.308213 1.264734 1.254106 1.245089 1.227375
## cells retained by counts ( 800 ): 2775
## percentage of retained cells: 26.79 %
dir.create("result")
saveRDS(dat, file = "./result/SAMN19314103_clean_QC.Rds")
#Normalize
dat <- NormalizeData(dat)
# Find the first 4000 variabe features
dat <- FindVariableFeatures(dat, selection.method = "vst", nfeatures = 4000)
Set mean expression to 0 and variance across 1 to avoid highly expressed genes drive the forwarding analyses. Since negative expression is meaningless, scaled data are useful only for UMAP and clustering
# scale data, the scaled data are saved in:
# dat[["RNA"]]@scale.data
all.genes <- rownames(dat)
dat <- ScaleData(dat, vars.to.regress = c("percent_mt","nCount_RNA"))
dat <- RunPCA(dat, features = VariableFeatures(object = dat), verbose = F, seed.use = 1)
print(dat[["pca"]], dims = 1:5, nfeatures = 5)
## PC_ 1
## Positive: PTMA, TXNIP, HNRNPA2B1, CORO1A, ARHGDIB
## Negative: IGLC1, IGHG3, IGHGP, HIST1H2BG, IGHG2
## PC_ 2
## Positive: STMN1, HBB, HBA1, BLVRB, HBA2
## Negative: JUN, UBC, KLF6, H3F3B, TSC22D3
## PC_ 3
## Positive: TXNIP, LINC01781, COBLL1, IGHG1, B2M
## Negative: LMNA, AHNAK, ANKRD28, ID2, VIM
## PC_ 4
## Positive: RPS18, GAS5, RPS14, RPL18, RPS2
## Negative: IGHG3, IGHGP, IGHG1, IGHG2, IGLC1
## PC_ 5
## Positive: HBB, CCL3, HBA1, HBA2, CCL3L1
## Negative: RPS14, RPS18, RPS4X, B2M, RPL5
UMAP is a graph-based method of clustering. The first step in this process is to construct a KNN graph based on the euclidean distance in PCA space:
dat <- FindNeighbors(dat, dims = 1:20)
The graph now can be used as input for the function
runUMAP()
dat <- RunUMAP(dat, dims = 1:20, seed.use = 1)
DimPlot(dat, reduction = 'umap', seed = 1)
## QC metrics
## markers
## Warning in FeaturePlot(dat, features = c("SDC1", "NCAM1", "HBB", "SLAMF7"), :
## All cells have the same value (0) of NCAM1.